package com.hsjk.szwj.module.train.controller.admin;

import com.hsjk.szwj.framework.common.pojo.CommonResult;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminSetSkuDivisionReqVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminSkuDivisionListRespVO;
import com.hsjk.szwj.module.train.service.ISkuDivisionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static com.hsjk.szwj.framework.common.pojo.CommonResult.success;

/**
 * @author chenjiawei
 * @desc
 * @Date 2023/12/04 22:49
 **/
@Tag(name = "管理端 - sku分账相关接口")
@RestController
@RequestMapping("/sku/division")
@Validated
@Slf4j
public class AdminSkuDivisionController {
    @Resource
    private ISkuDivisionService skuDivisionService;

    @PostMapping("/batch-create")
    @Operation(summary = "批量添加sku分账规则")
    @PreAuthorize("@ss.hasPermission('sku:division:create')")
    public CommonResult<Boolean> batchCreateSkuDivision(@RequestBody @Valid List<AdminSetSkuDivisionReqVO> reqVO) {
        return success(skuDivisionService.batchCreateSkuDivision(reqVO));
    }

    @GetMapping("/get-by-sku-id")
    @Operation(summary = "根据sku id获取分账信息")
    @PreAuthorize("@ss.hasPermission('sku:division:query')")
    public CommonResult<List<AdminSkuDivisionListRespVO>> getAdminSkuDivisionListBySkuId(@RequestParam Long skuId) {
        return success(skuDivisionService.getAdminSkuDivisionListBySkuId(skuId));
    }
}
